#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:Fight.py
# author:张世航
# datetime:2024/11/12 23:56
# software: PyCharm
"""
this is function  description 
"""
# import module your need

import random
from Human import Human
from Dog import Dog


class Fight:
    def __init__(self):
        self.humans = [Human("Human1"), Human("Human2")]
        self.dogs = [Dog("Dog1"), Dog("Dog2"), Dog("Dog3")]
        self.turn = random.choice(["human", "dog"])

    def start(self):
        while any(human.is_alive() for human in self.humans) and any(dog.is_alive() for dog in self.dogs):
            if self.turn == "human":
                self.human_attack()
                self.turn = "dog"
            else:
                self.dog_attack()
                self.turn = "human"

            # Check if all humans or all dogs are dead
            if not any(human.is_alive() for human in self.humans):
                print("All humans are dead. Dogs win!")
                break
            if not any(dog.is_alive() for dog in self.dogs):
                print("All dogs are dead. Humans win!")
                break

    def human_attack(self):
        alive_dogs = [dog for dog in self.dogs if dog.is_alive()]
        if not alive_dogs:
            return

        attacker = random.choice([human for human in self.humans if human.is_alive()])
        target = random.choice(alive_dogs)
        attacker.attack(target)

    def dog_attack(self):
        alive_humans = [human for human in self.humans if human.is_alive()]
        if not alive_humans:
            return

        attacker = random.choice([dog for dog in self.dogs if dog.is_alive()])
        target = random.choice(alive_humans)
        attacker.attack(target)


if __name__ == "__main__":
    fight = Fight()
    fight.start()